package cc.flyflow.web.controller.org;

import cc.flyflow.biz.org.entity.User;
import cc.flyflow.biz.org.service.IOrgService;
import cc.flyflow.biz.org.service.IUserBizService;
import cc.flyflow.biz.org.service.IUserService;
import cc.flyflow.biz.vo.UserBizVO;
import cc.flyflow.biz.vo.UserListQueryVO;
import cc.flyflow.common.dto.R;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户接口
 */
@RestController
@RequestMapping(value = {"user"})
public class UserController
{

    @Resource
    private IUserService userService;

    @Resource
    private IUserBizService userBizService;

    @Resource
    private IOrgService orgService;

    /**
     * 创建用户
     *
     * @param user
     * @return
     */
    @PostMapping("create")
    public R create(@RequestBody UserBizVO user)
    {
        return userService.createUser(user);
    }

    /**
     * 修改用户
     *
     * @param user
     * @return
     */
    @PutMapping("edit")
    public R editUser(@RequestBody UserBizVO user)
    {
        return userService.editUser(user);
    }

    /**
     * 修改密码
     *
     * @param user
     * @return
     */
    @PostMapping("password")
    public R password(@RequestBody User user)
    {
        return userService.password(user);
    }

    /**
     * 修改状态
     *
     * @param user
     * @return
     */
    @PostMapping("status")
    public R status(@RequestBody User user)
    {
        return userService.status(user);
    }

    /**
     * 获取当前用户详细信息
     *
     * @return
     */
    @SneakyThrows
    @GetMapping("getCurrentUserDetail")
    public R getCurrentUserDetail()
    {
        return userBizService.getCurrentUserDetail();
    }

    /**
     * 获取用户详细信息
     *
     * @param userId
     * @return
     */
    @GetMapping("getUserDetail")
    public R getUserDetail(String userId)
    {
        return orgService.getUserDetail(userId);
    }

    /**
     * 查询用户列表
     *
     * @param userListQueryVO
     * @return
     */
    @PostMapping("queryList")
    public R queryList(@RequestBody UserListQueryVO userListQueryVO)
    {
        return userBizService.queryList(userListQueryVO);
    }

    /**
     * 删除用户
     *
     * @param userListQueryVO
     * @return
     */
    @DeleteMapping("delete")
    public R delete(@RequestBody User userListQueryVO)
    {
        return orgService.delete(userListQueryVO);
    }
}
